from Data import search_file
from Data import pDFConversion
from Data.Chinese import pdf
from Data.Chinese import model_number_catalogue

sys_flag = False


def one_click_publishing(is_svn, options=None):
    global sys_flag
    if options is None:
        options = {
            'module_number': False,
            'pdf_conversion': False,
            'pdf_hebing': False,
        }
    # filepaths = search_file.select_folder()
    # if filepaths == "-1":
    #     return "-1"
    if options.get("module_number") and options.get("pdf_conversion") and options.get("pdf_hebing"):
        sys_flag = True
        is_filepaths = model_number_catalogue.model_number(is_svn, False)
        if is_filepaths == "-1":
            return "-1"
        filepaths = model_number_catalogue.updated_paths
        sysop_flag = model_number_catalogue.sysop_flag
        if sysop_flag:
            print("编号异常，程序中断")
            return

        pDFConversion.pdf_conversion(filepaths)
        sysop_flag = pDFConversion.sysop_flag
        pdf_paths = pDFConversion.pdf_paths
        if sysop_flag:
            print("PDF转换异常，程序中断")
            return

        pdf.pdf_collaboration("SCG/CREF合稿", pdf_paths)
        sysop_flag = pDFConversion.sysop_flag
        if sysop_flag:
            print("PDF转换异常，程序中断")
            return

    if not options.get("module_number") and options.get("pdf_conversion") and options.get("pdf_hebing"):
        sys_flag = True

        is_filepaths = pDFConversion.pdf_conversion(None)
        if is_filepaths == "-1":
            return "-1"
        sysop_flag = pDFConversion.sysop_flag
        pdf_paths = pDFConversion.pdf_paths
        if sysop_flag:
            print("PDF转换异常，程序中断")
            return

        pdf.pdf_collaboration("SCG/CREF合稿", pdf_paths)
        sysop_flag = pDFConversion.sysop_flag
        if sysop_flag:
            print("PDF转换异常，程序中断")
            return

    if not options.get("module_number") and not options.get("pdf_conversion") and options.get("pdf_hebing"):
        sys_flag = True

        is_filepaths = pdf.pdf_collaboration("SCG/CREF合稿", None)
        if is_filepaths == "-1":
            return "-1"
        sysop_flag = pDFConversion.sysop_flag
        if sysop_flag:
            print("PDF转换异常，程序中断")
            return


if __name__ == '__main__':
    one_click_publishing(["模块编号", "PDF转换", "PDF合稿"], True, False)
